﻿#include "BinaryTreeNode.h"

#define MAX(a, b) ((a > b) ? a : b)

BinaryTreeNode::BinaryTreeNode(int value)
{
    this->value = value;
    left = nullptr;
    right = nullptr;
    parent = nullptr;
}

BinaryTreeNode::~BinaryTreeNode()
{
}

static size_t _getDepth(BinaryTreeNode* head)
{
    if (!head) return 0;

    size_t leftDepth = _getDepth(head->left);
    size_t rightDepth = _getDepth(head->right);
    return 1 + MAX(leftDepth, rightDepth);
}

size_t BinaryTreeNode::getDepth(BinaryTreeNode* head)
{
    if (!head) head = this;

    return _getDepth(head);
}

static size_t _getNodeCount(BinaryTreeNode* head)
{
    if (!head) return 0;

    return 1 + _getNodeCount(head->left) + _getNodeCount(head->right);
}

size_t BinaryTreeNode::getNodeCount(BinaryTreeNode* head)
{
    if (!head) head = this;

    return _getNodeCount(head);
}
